package com.example.crm.controller;

import com.example.crm.entity.User;
import com.example.crm.service.IUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户控制器
 * @author lenovo
 */
@RestController
public class UserController {
    @Resource
    private IUserService userService;

    @GetMapping("/users")
    public List<User> findAllUsers() {
        List<User> list = userService.findAllUsers();
        return list;
    }

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id") Long usrId){
        User user = userService.getUser(usrId);
        return user;
    }

    @PostMapping("/user")
    public void addUser(User user){
        userService.addUser(user);
    }

    @PutMapping("/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }

    @DeleteMapping("/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId){
        userService.deleteUser(usrId);
    }
}